<?php
/**
 * @version		$Id:  $
 * @package		Success Framework Mobile
 * @subpackage	Controller
 * @copyright	Copyright (C) 2007 - 2010 Success company - VietNam. All rights reserved.
 */
defined('PATH_BASE') or die();
/**
 * Object class, allowing __construct in PHP4.
 *
 * @package		Success.Framework
 * @subpackage	Base
 * @since		1.0
 */
 
class sscls_Controller extends sscls_Router
{
    
    var $layout;
    
    var $view;

    
    function display($tmpValue=array())
    {
        $this->tmpValue=$tmpValue;
        parent::display($this->view,$this->layout);
    }
    
    
    function getModel($name='')
    {
        if($name=='')
        {
            $name=$this->getController();
        }
    
        sscls_File::load(PATH_MODEL.$name.'.php');
        $classname="sscls_".ucwords($name)."Model";
        return new $classname();  
    }
    
    function setRedirec($url='',$msg='',$type='info')
    {
        sscls_Router::redirec($url,$msg,$type);
        return true;
    }
    
    function msgRedirect($data){
        $session=ss_Main::getSession();                                                
        ini_set('session.cookie_lifetime',1000);        
        $session->set('objMsg',$data);
        $this->setRedirec('index.php?c=anderen&t=message', NULL);
    }
    
    function getObjMsg(){
        $session=ss_Main::getSession();                                                        
        return $session->get('objMsg');
    }
    
    function clearObjMsg()
    {
        $session=ss_Main::getSession();                                                        
        $session->set('objMsg', null);    
    }
    
    function sendmail($from, $to, $subject, $body)
    {
        require_once "Mail.php";            

        //$from = "Sender <sender@example.com>";
        //$to = "Recipient <recipient@example.com>";
        //$subject = "Hi!";
       // $body = "Hi,\n\nThis is a test!";   

        $host = SMTP;
        $username = SMTP_USER;
        $password = SMTP_PASS;   

        $headers = array ('From' => $from,
          'To' => $to,
          'Subject' => $subject);
        $smtp = Mail::factory('smtp',
          array ('host' => $host,
            'auth' => true,
            'username' => $username,
            'password' => $password));   

        $mail = $smtp->send($to, $headers, $body);   

        if (PEAR::isError($mail)) {
          //echo("<p>" . $mail->getMessage() . "</p>");
          return $mail->getMessage();
         } else {
          //echo("<p>Message successfully sent!</p>");
          return '';
         }

        /*$host = SMTP;
        $username = SMTP_USER;
        $password = SMTP_PASS;

        $headers = array ('From' => $from,
        'To' => $to,
        'Subject' => $subject);
        $smtp = Mail::factory('smtp',
        array ('host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password));

        $mail = $smtp->send($to, $headers, $body);

        if (PEAR::isError($mail)) {
            return false;
        } else {
            return true;
        }*/
    }    
	
	//Check valid email
	//@return true if email is valid, else is invalid
	//@author ThieuLe
	
	 function isValidEmail($email){
      $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
     
      if (eregi($pattern, $email)){
         return true;
      }
      else {
         return false;
      }   
   }
} 
?>

